#include "StdAfx.h"
#include "SDKInterface.h"

#define DLL_NAME	"TEX0_SDK.dll"
#define INI_FILE		"eSDKClientLogCfg.ini"
#define LOG_NAME	"log"

CSDKInterface::CSDKInterface(void)
{
	string dllPath = GetDllPath(DLL_NAME);
	string iniFile = dllPath + INI_FILE;
	string logPath = dllPath + LOG_NAME;
	unsigned int logLevel[LOG_CATEGORY] = {INVALID_LOG_LEVEL, INVALID_LOG_LEVEL, INVALID_LOG_LEVEL};
	LogInit(PRODUCT_NAME, iniFile.c_str(), logLevel, logPath.c_str());
	m_LoginMgr.SetInterfaceObj(this);
	m_SubscriptionMgr.SetInterfaceObj(this);
	m_AddrBookMgr.SetInterfaceObj(this);
	m_CallMgr.SetInterfaceObj(this);
	m_ConfMgr.SetInterfaceObj(this);
	m_MediaCtrlMgr.SetInterfaceObj(this);
}


CSDKInterface::~CSDKInterface(void)
{
	LogFini(PRODUCT_NAME);
}


string CSDKInterface::GetDllPath(string dllName)
{
	HMODULE hModule = GetModuleHandleA(dllName.c_str());
	if(NULL == hModule)
	{
		return "";
	}
	char dllpath[MAX_PATH];
	memset(dllpath, 0, sizeof(dllpath));
	::GetModuleFileNameA(hModule, dllpath, MAX_PATH);
	std::string strPath(dllpath);
	strPath = strPath.substr(0, strPath.rfind("\\")+1);
	return strPath;
}

int CSDKInterface::StartKeepAlive()
{
	TEX0_DEBUG_TRACE("");

	return m_SubscriptionMgr.StartMsgRetrieval();
}

int CSDKInterface::StopKeepAlive()
{
	TEX0_DEBUG_TRACE("");

	return m_SubscriptionMgr.StopMsgRetrieval();
}
